from os import path

from flask import Blueprint, request, send_file

assets = Blueprint('assets', __name__)
basepath = path.join(path.dirname(path.abspath(__file__)), r'..\..\assets')


@assets.route('/get')
def get_assets():
    uuid = dict(request.args).get('id')
    file_path = path.join(basepath, uuid)
    if not path.exists(file_path):
        raise Exception("文件不存在")
    return send_file(file_path, as_attachment=True, attachment_filename=uuid)
